<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no" />
	<title>娱管家</title>  
    <meta name="format-detection" content="telephone=no">
    <meta name="msapplication-tap-highlight" content="no">
    <meta name="x5-orientation" content="portrait">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Access-Control-Allow-Origin" content="">
	<meta http-equiv="content-security-policy">
	<script type="text/javascript" src="js/jquery.min.js" ></script>
	<!--mui样式-->
	<link rel="stylesheet" type="text/css" href="css/mui.min.css"/>
	<link rel="stylesheet" type="text/css" href="css/mui/app.css"/>
	<link rel="stylesheet" type="text/css" href="css/mui/mui.picker.css"/>
	<link rel="stylesheet" type="text/css" href="css/mui/mui.picker.min.css"/>
	<link rel="stylesheet" type="text/css" href="css/mui/mui.poppicker.css"/>
	<!--环信-->
	<script type="text/javascript" src="js/hx/strophe.js" ></script>
	<script type="text/javascript" src="js/hx/websdk-1.1.2.js"></script>
	<script type="text/javascript" src="js/hx/websdk.config.js"></script>
	<script type="text/javascript" src="js/hx/websdk.shim.js"></script> 
	<script type="text/javascript" src="js/bq.js"></script> 
	<!--环信-->
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=yWnFso0oyjmX79HzCx1DRz2sBtvweQfI"></script>
	<link rel="stylesheet" href="css/loding/fakeLoader.css"/>
	<!--头像上传-->
	<link rel="stylesheet" href="css/cropper.css"/>
	<script src="js/cropper.js"></script>
	<!-- 公共样式与字体  -->
	<link rel="stylesheet" href="css/public.css"/>
	<link rel="stylesheet" type="text/css" href="icon-font/iconfont.css"/>
	<!-- 定制样式   -->
	<link rel="stylesheet" href="css/style.css"/>
	<link rel="stylesheet" href="css/bq.css" />
	<link rel="stylesheet" type="text/css" href="css/NewStyle.css"/>
	<!-- Swiper 样式  -->
	<link rel="stylesheet" type="text/css" href="css/swiper.min.css"/>
	<link rel="stylesheet" href="css/appstyle.css" />
	<!-- 微信分享 -->
	<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
	<style type="text/css">
		.rgba{display: none;}
	</style>
</head>
<body>
	<div class="App">
		<span>娱管家</span>
		<button>下载APP</button>
	</div>
	<div class="pHead mui-navbar-inner mui-bar mui-bar-nav header_1 RepairInfo" >
		<h2>维修预约</h2>
		<!--<span class="iconfont icon-pingjia"></span>-->
	</div>
	<div class="pBody mui-page-content RepairInfo">
		<div class="HeadImg">
			<img src="images/1.jpg"/>
		</div>
		<div class="ContentMain">
			<p class="info">
				<span class="name">name</span>
				<span class="phone">phone</span>
			</p>
			<p class="address iconfont icon-dingwei">地址</p>
			<p class="content">内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容</p>
		</div>
		<div class="RepairComment">
			<h2>用户评价</h2>
			<ul>
				<li>
					<p>
						<span>name</span>
						<span>time</span>
					</p>
					<p>Content</p>
				</li>
			</ul>
		</div>
		<div class="popComment">
			<div class="popCommentMain">
				<div class="title">
					<h2>评论</h2>
					<span class="iconfont icon-cha"></span>						
				</div>
				<p class="score">
					<span class="iconfont icon-wujiaoxing"></span>
					<span class="iconfont icon-wujiaoxing"></span>
					<span class="iconfont icon-wujiaoxing"></span>
					<span class="iconfont icon-wujiaoxing"></span>
					<span class="iconfont icon-wujiaoxing"></span>
				</p>
				<div class="content">
					<textarea name="" rows="" cols="" placeholder="请输入评论内容"></textarea>
					<button id="popCommentBtn">提交</button>
				</div>
			</div>
		</div>
		<button class="RepairListInfoBtn">立即维修<a href=""></a></button>
	</div>
	<div class="rgba"></div>
	<div class="" id="tan2"></div>
	<script src="js/muijs/mui.min.js"></script>
	<script src="js/muijs/mui.picker.min.js"></script>
	<script src="js/muijs/mui.poppicker.js"></script>
	<script src="js/base.js"></script>
	<script src="js/swiper.min.js"></script>
	<script type="text/javascript">
		var share_link = location.href;
		var share_data = {
	        title: '娱管家',// 设置分享标题
	        desc: '',// 设置分享描述
	        link: share_link,// 设置分享链接
	        img: ''// 分享图片
	    };
		function tan(text2){
			$("#tan2").addClass("tan");
			$("#tan2").text(text2);
			clearTimeout(a);
			var a = setTimeout (function(){
				ding();
			},2000);
			function ding (){
				$("#tan2").removeClass("tan");
				$("#tan2").text("");
			};
		}
		function getCache(key){
			if(localStorage.getItem(key)){
				return JSON.parse(localStorage.getItem(key));
			}else{
				return false;
			}
		}		
		var token = GetQueryString('token');
		$('.App button').unbind('click').on('click',function(){
			location.href = 'http://www.yuzhuli.com/Share/erweima.html?id='+token;
		});
		function initLBT(boxId,dataList){
			$('#'+boxId).empty();
			$('#'+boxId).html('<div class="swiper-container swiper_'+boxId+'"><div class="swiper-wrapper SwiperImg_'+boxId+'" style="font-size: 0;"></div><div class="swiper-pagination SwiperSpot_'+boxId+'"></div></div>');
			var html = '';
			$.each(dataList,function(i,d){
				html += '<div class="swiper-slide"><img src="' + d + '"></div>';
			});
			$('.SwiperImg_'+boxId).html(html);
			LBT('.swiper_'+boxId,'.SwiperSpot_'+boxId);
		}
	    function LBT(swiper1,swiper2) {
			//轮播图
			var swiper = new Swiper(swiper1, {
				pagination: swiper2,
				paginationClickable: true,
				loop:true
			});
			swiper.update();
		}
	    
	    function GetQueryString(name){
		    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
		    var r = window.location.search.substr(1).match(reg);
		    if(r!=null)return  unescape(r[2]); return null;
		}
	    
	    
	    
		var parm = GetQueryString('id');
		var starindex = 0;
		var hm = $(window).height() - $('.DetailsInfo').height() -$('.DetailsInfo').height() - $('.pHead.header_1').height();
		
		$('.pBody.RepairInfo').height(hm).css({'overflow-y':'scroll','-webkit-overflow-scrolling':'touch'});
		
		$('.icon-pingjia').unbind('tap').on('tap',function(){
			$('.popComment').fadeIn(function(){
				closePop();
				star();
			});
		});
		
		function star(){
			$('.popCommentMain .score span').unbind('tap').on('tap',function(){
				$('.popCommentMain .score span').css('color','#eee');
				starindex = $(this).index();
				starindex++;
				$('.popCommentMain .score span').slice(0,starindex).css("color","#ff9d09");
			})
		}
		
		function closePop(){
			var dom = $('.popComment');
			dom.find('.icon-cha').unbind('tap').on('tap',function(){
				dom.fadeOut();
			});
		}
		
		//   *************** 获取数据  ******************
		function getComment(){
			var token = getCache('token');
			var url = 'http://www.yuzhuli.com/api.php/Api/maintainer_info';
			$.post(url,{id:parm,token:token},function(obj){
				if(obj.s){
					var obj = obj.d;
					$('.ContentMain .info .name').text(obj.name);
					$('.HeadImg img').attr('src',obj.img);
					$('.ContentMain .info .phone').text(obj.mobile);
					$('.ContentMain .content').text(obj.assessment != ''?obj.assessment:'暂无介绍' );
					$('.ContentMain .address').text(obj.address);
					$('.DetailsInfo p').eq(0).text(obj.address);
					$('.DetailsInfo p').eq(1).text(obj.mobile);
					$('.RepairListInfoBtn a').attr('href','tel:'+obj.mobile);
//					var bhtml = '<b style="float: right;color: #28aa32;font-size: 0.4rem;" class="iconfont icon-weixin"></b>';
//					$('.ContentMain .info').append(bhtml);
					var html = '';
					$.each(obj.comments,function(i,d){
						html += '<li><p><span>'+d.nickname+'</span><span>'+d.time+'</span></p><p>'+d.content+'</p></li>';
					});
					$('.RepairComment ul').html(html);

					share_data.title = obj.name;
				    share_data.desc = obj.mobile+','+ obj.address;
				    share_data.img = obj.img;
				    getWxConfig(ApiList, wxConfigCallback, false);
				}else{
					tan(obj.m);
				}
			});
		}
		getComment();
		
		// 维修评论
	    $("#popCommentBtn").unbind('tap').on('tap',function(){
	    	var content = $('.popCommentMain textarea').val();
			var token = getCache('token');
			if(token){
				if(content){
				    Api.post(Api.add_comment,{type:'maintainer',id:parm,content:content,score:starindex},function(obj){
				    	if(obj.s){
				    		fun.tan("评论成功");
							getComment();
				    		$('.popComment').fadeOut();
				    	}else{
				    		fun.tan("评论失败");
				    	}
				    });
				}else{
					mui.toast('内容不能为空')
				}
			}else{
				fun.tan('请先登录');
			}
	    });
	     // 分享
	    function getWxConfig(ApiList, callback, debug) {    		
	        $.ajax({
	            url: 'http://www.yuzhuli.com/api.php/api/wechat_js_config',
	            type: 'POST',
	            dataType: 'json',
	            data: {url: location.href,apis:ApiList,debug:debug},
	        }).done(function (res) {
	        	console.log(res);
	            if (res.s) {
	                var con = res.config;
	                var wxConf = {
	                    debug: debug,
	                    appId: con.appId,
	                    timestamp: con.timestamp,
	                    nonceStr: con.nonceStr,
	                    signature: con.signature,
	                    jsApiList: ApiList
	                };
	                wx.config(wxConf);
	                wx.ready(function () {
	                    callback();
	                });
	            }
	        }).fail(function () {
	            console.log("error");
	        }).always(function () {
	            console.log("complete");
	        });
	    }
	    var ApiList = [
	        'onMenuShareTimeline',
	        'onMenuShareAppMessage',
	        'onMenuShareQQ',
	        'onMenuShareQZone',
	        'onMenuShareWeibo',
	    ];	
	    
	    function wx_share(data, callback) {
	        // 分享到朋友圈
	        wx.onMenuShareTimeline({
	            title: data.title, // 分享标题
	            link: data.link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
	            imgUrl: data.img, // 分享图标
	            success: function () {
	                // 用户确认分享后执行的回调函数
	            },
	            cancel: function () {
	                // 用户取消分享后执行的回调函数
	            }
	        });
	        // 分享给朋友
	        wx.onMenuShareAppMessage({
	            title: data.title, // 分享标题
	            desc: data.desc, // 分享描述
	            link: data.link, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
	            imgUrl: data.img, // 分享图标
	            type: '', // 分享类型,music、video或link，不填默认为link
	            dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
	            success: function () {
	                // 用户确认分享后执行的回调函数
	            },
	            cancel: function () {
	                // 用户取消分享后执行的回调函数
	            }
	        });
	        wx.onMenuShareQQ({
				title: data.title, // 分享标题
				desc: data.desc, // 分享描述
				link: data.link, // 分享链接
				imgUrl: data.img, // 分享图标
				success: function () {
				// 用户确认分享后执行的回调函数
				},
				cancel: function () {
				// 用户取消分享后执行的回调函数
				}
			});
			wx.onMenuShareQZone({
				title: data.title, // 分享标题
				desc: data.desc, // 分享描述
				link: data.link, // 分享链接
				imgUrl: data.img, // 分享图标
				success: function () {
				// 用户确认分享后执行的回调函数
				},
				cancel: function () {
				// 用户取消分享后执行的回调函数
				}
			});
			wx.onMenuShareWeibo({
				title: data.title, // 分享标题
				desc: data.desc, // 分享描述
				link: data.link, // 分享链接
				imgUrl: data.img, // 分享图标
				success: function () {
				// 用户确认分享后执行的回调函数
				},
				cancel: function () {
				// 用户取消分享后执行的回调函数
				}
			});
	    }	
	    var shareCallback = function (type, status) {
			
	    }	
	    var wxConfigCallback = function () {
//	    	$("audio")[0].play();
	        wx_share(share_data, shareCallback);	        
	    }	
	    
	    wx.error(function (res) {
	        console.log(JSON.stringify(res));
	        // config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名。
	    }); 
	</script>
</body>
</html>
